home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / AnimeNfo.ifs < prev    next >
Text File  |  2005-03-13  |  8KB  |  253 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Mrknife
  8. Title=AnimeNfo
  9. Description=AnimeNfo (US)
  10. Site=http://www.animenfo.com
  11. Language=EN
  12. Version=
  13. Requires=3.5.0
  14. Comments= This was slapped together from the script IMDB that was included with version 3.4.3| !!  Country and Language are always set to Japan/Japanese| !!  Only the First Category will be used| !!  You will always have to select a title, even when the list is only 1 option
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program AnimeNfo;
  23.  
  24. uses
  25.   StringUtils1;
  26.  
  27. var
  28.   MovieName: string;
  29.   MovieURL: string;
  30.   MovieNumber: string;
  31.  
  32. // ***** analyzes the results page that asks to select a movie from a list *****
  33.  
  34. procedure AnalyzeResultsPage(Address: string);
  35. var
  36.   PageText: string;
  37.   Value: string;
  38. begin
  39.   PageText := GetPage(Address);
  40.   if pos('<font color=''#FFFFFF''><b> Search Result', PageText) = 0 then
  41.   begin
  42.     AnalyzeMoviePage(PageText)
  43.   end else
  44.   begin
  45.  
  46.     PickTreeClear;
  47.     repeat
  48.       Value := 'results:';
  49.       if Value <> '' then
  50.       begin
  51.         HTMLRemoveTags(Value);
  52.         HTMLDecode(Value);
  53.         PickTreeAdd(Value, '');
  54.       end;
  55.       Value := TextBetween(PageText, 'Search Result', 'End Contents');
  56.       PageText := RemainingText;
  57.     until not AddMovieTitles(Value);
  58.     Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
  59.     if Value <> '' then
  60.       PickTreeMoreLink('http://www.animenfo.com/animetitle' + Value );
  61.     if PickTreeExec(Address) then
  62.       AnalyzeResultsPage(Address);
  63.   end;
  64. end;
  65.  
  66. // ***** adds the titles contained in <ol>'s items *****
  67.  
  68. function AddMovieTitles(List: string): Boolean;
  69. var
  70.   Value: string;
  71.   Name: String;
  72.   Address: string;
  73. begin
  74.   Result := False;
  75.   Value := TextBetween(List, 'href=''animetitle', 'html''>');
  76.   Name := TextBetween(List, 'html''>', '</a>');
  77.   List := RemainingText;
  78.   while Value <> '' do
  79.   begin
  80.     Address := Value+'html';
  81.     HTMLRemoveTags(Value);
  82.     HTMLDecode(Value);
  83.     PickTreeAdd(Name, 'http://www.animenfo.com/animetitle' + Address);
  84.     Result := True;
  85.     Value := TextBetween(List, 'href=''animetitle', 'html''>');
  86.     Name := TextBetween(List, 'html''>', '</a>');
  87.     List := RemainingText;
  88.   end;
  89. end;
  90.  
  91. // ***** analyzes the page containing movie information *****
  92.  
  93. procedure AnalyzeMoviePage(PageText: string);
  94. var
  95.   Value, Value2, Value3, FullValue, MovieT, MovieTitle_Html,CHar11 ,SEiyu : string;
  96. begin
  97.   MovieNumber := TextBetween(PageText, '/anime/episode/display.php?id=', '&n=');
  98.   MovieT := TextBetween(PageText, '&n=', '&t=');
  99.   MovieTitle_Html := TextBetween(PageText, '&t=', '''>');
  100.  
  101.   MovieURL := 'http://www.animenfo.com/animetitle,' + MovieNumber + ',' + MovieT + ',' + MovieTitle_Html + '.html';
  102.   // URL
  103.   if CanSetField(fieldURL) then
  104.     SetField(fieldURL, MovieURL);
  105.  
  106.   // Original Title & Year
  107.   if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
  108.   begin
  109.     Value := TextBetween(PageText, '<title>AnimeNfo.Com : Anime : ', '</title>');
  110.   //  Value2 := TextBefore(Value, ' (', '');
  111. //    Value := RemainingText;
  112.  //   HTMLDecode(Value2);
  113.     if CanSetField(fieldOriginalTitle) then
  114.       SetField(fieldOriginalTitle, Value);
  115.     Value2 := TextBetween(PageText, 'animebyyear.php?year=', '''>');
  116.     if CanSetField(fieldYear) then
  117.       SetField(fieldYear, Value2);
  118.   end;
  119.   // Rating
  120.   if CanSetField(fieldRating) then
  121.   begin
  122.     Value := TextBetween(PageText, 'User Rating</font></td><td valign=''top'' bgcolor=''#F0F0F0''><font class=''DefaultFont''', '/10.0');
  123.     Value2 := TextBetween(Value, '>', '.');
  124.     if StrToInt(Copy(RemainingText, 1, 1), 0) >= 5 then
  125.       Value2 := IntToStr(StrToInt(Value2, 0) + 1);
  126.     SetField(fieldRating, Value2);
  127.   end;
  128.   // Picture     NOT WORKING RIGHT NOW
  129.  ImportSmallPicture(PageText);
  130.  
  131.   // Director
  132.   if CanSetField(fieldProducer) then
  133.   begin
  134.     Value := TextBetween(PageText, 'Studio</font></td>', '<br></font></td></tr>');
  135.     Value2 := TextBefore(Value, '</a>','</script>');
  136.     SetField(fieldProducer, Value2);
  137.   end;
  138.  
  139.   // Actors            working
  140.   if CanSetField(fieldActors) then
  141.   begin
  142.     SEiyu := 'garbage';
  143.     Value := TextBetween(PageText, 'Seiyuu (Voice Talent)</font>', 'Explanation');
  144.     //SetField(fieldActors, Value);
  145.     if Value <> '' then
  146.     begin
  147.       FullValue := '';
  148.           while Value <> '' do
  149.           begin
  150.             CHar11 := TextBetween(Value, 'href=''/anime/character/display', '</a></td><td valign')+'***';
  151.             Value := RemainingText;
  152.             CHar11 := TextBetween(CHar11, '>', '***');
  153.             if CHar11 = '' then
  154.               Break;
  155.             SEiyu := TextBetween(Value, '</script>', '</a></td><td valign');
  156.             Value := RemainingText;
  157.             FullValue := FullValue + SEiyu + ' (as ' + CHar11 + ')' + #13#10;
  158.           end;
  159.  
  160.       HTMLRemoveTags(FullValue);
  161.       HTMLDecode(FullValue);
  162.  
  163.       SetField(fieldActors, FullValue);
  164.     end;
  165.   end;
  166.  
  167.   //Country       Set to Japan
  168.   if CanSetField(fieldCountry) then
  169.   begin
  170.     SetField(fieldCountry, 'Japan');
  171.   end;
  172.  
  173.   //Category      Can only get the First Catagory
  174.   if CanSetField(fieldCategory) then
  175.   begin
  176.     Value := TextBetween(PageText, '<font class=''DefaultFont''>Genres', ', <a');
  177.     Value2 := TextBefore(Value, '</a>','>');
  178.  
  179.     SetField(fieldCategory, Value2);
  180.   end;
  181.  
  182.   // Language      Set to Japanese
  183.   if CanSetField(fieldLanguages) then
  184.   begin
  185.     SetField(fieldLanguages, 'Japanese');
  186.   end;
  187.  
  188.   //Description
  189.   if CanSetField(fieldDescription) then
  190.   begin
  191.      Value := TextBetween(PageText, 'Description </b></font>', '</font></td></tr></table><br><table border=');
  192.      Value2 := TextAfter(Value, '<font class=''DefaultFont''>');
  193.      HTMLRemoveTags(Value2);
  194.      HTMLDecode(Value2);
  195.      SetField(fieldDescription, Value2);
  196.   end;
  197.  
  198.   // Comments
  199.   if CanSetField(fieldComments) then
  200.   begin
  201.     Value := TextBetween(PageText, 'Total Episodes</font></td><td valign=''top'' bgcolor=''#F0F0F0''><font class=''DefaultFont''>', '</font>');
  202.      HTMLRemoveTags(Value);
  203.      HTMLDecode(Value);
  204.     SetField(fieldComments, 'Total Episodes: '+Value);
  205.  
  206.   end;
  207. end;
  208.  
  209. // ***** functions to import the different pictures kinds, depending of the option selected by user *****
  210.  
  211. function ImportSmallPicture(PageText: string): Boolean;
  212.  
  213. var
  214.   Value: string;
  215. begin
  216.   Result := False;
  217.   Value := TextBetween(PageText, '<img border=''0'' ', 'font class=''DefaultFont''>Title');
  218.   Value := TextBetween(Value, 'Src=''', ''' width');
  219.  
  220.   if Value <> '' then
  221.   begin
  222.     GetPicture(Value);
  223.     Result := True;
  224.   end;
  225. end;
  226.  
  227.  
  228. // ***** beginning of the program *****
  229.  
  230. begin
  231.   if CheckVersion(3,5,0) then
  232.   begin
  233.     MovieName := GetField(fieldOriginalTitle);
  234.     if MovieName = '' then
  235.       MovieName := GetField(fieldTranslatedTitle);
  236.     if not Input('AnimeNfo Import', 'Enter the name of the anime Series :', MovieName) then
  237.       Exit;
  238.     if MovieName <> '' then
  239.     begin
  240.       if Pos('AnimeNfo.com', MovieName) > 0 then
  241.         AnalyzeResultsPage(MovieName)
  242.       else
  243.       begin
  244.         MovieName := StringReplace(MovieName, '&', 'and');
  245.           AnalyzeResultsPage('http://www.animenfo.com/search.php?query='+UrlEncode(MovieName)+'&action=Go&queryin=anime_titles&option=keywords')
  246.        end;
  247.       //DisplayResults;
  248.     end;
  249.   end
  250.   else
  251.   ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  252. end.
  253.